import sys
import os
import uuid
from py2bc import _compile

with open(sys.argv[1], "r") as _f:
    data = _compile(_f.read(), sys.argv[1])
    with open(sys.argv[2], "w+b") as out:
        struct_name = uuid.uuid4().hex
        mod_name = os.path.splitext(os.path.basename(sys.argv[1]))[0]       
        struct_header = "unsigned char tp_%s[] = {" % struct_name
        out.write(struct_header)
        out.write( ",".join(["0x%x" % ord(d) for d in data]) )
        out.write("};\n")
        out.write( "tp_import(tp, 0, \"%(modname)s\", tp_%(structname)s, sizeof(tp_%(structname)s));" % {"structname":struct_name, "modname":mod_name} )
    
